import { defineStore } from 'pinia';
import { ref } from 'vue';
import type { UserInfo, Setting } from '../api/setting';

// 你可以任意命名 `defineStore()` 的返回值，但最好使用 store 的名字，同时以 `use` 开头且以 `Store` 结尾。
// (比如 `useUserStore`，`useCartStore`，`useProductStore`)
// 第一个参数是你的应用中 Store 的唯一 ID。
export const useUserInfoStore = defineStore('userInfo', () => {
  const userInfo = ref<UserInfo>({});
  function setUserInfo(data) {
    Object.assign(userInfo.value, data);
  }

  return { userInfo, setUserInfo };
});

export const useSettingStore = defineStore('setConfig', () => {
  const setting = ref<Setting>({});
  function setSetting(data) {
    Object.assign(setting.value, data);
  }

  return { setting, setSetting };
});

export const useContextMenuStore = defineStore('contextMenu', () => {
  const contextMenu = ref<any>({});
  function setContextMenu(data) {
    contextMenu.value = data;
  }

  const target = ref(null);
  function setTarget(val) {
    target.value = val;
  }

  const position = ref({ x: 0, y: 0 });
  function setPosition(event) {
    event && event.preventDefault && event.preventDefault();
    position.value = { x: event.clientX, y: event.clientY };
  }

  const menuActive = ref('');
  // 设置菜单选中项
  function setMenuActive(val) {
    menuActive.value = val;
  }
  const menuList=ref([])
  function setMenuList(val) {
    menuList.value = val;
  }
  return {
    contextMenu,
    setContextMenu,
    position,
    setPosition,
    menuActive,
    setMenuActive,
    setMenuList,
    menuList,
    target,
    setTarget,
  };
});

export const useIconListStore = defineStore('iconList', () => {
  const iconList = ref([]);
  function setIconList(data) {
    iconList.value = data;
  }

  return { iconList, setIconList };
});
